using System;
using System.Configuration;

namespace LocalBoard.Persistence.SqlAccessor
{
	/// <summary>
	/// Summary description for SqlDataAccessBase.
	/// </summary>
	public class SqlDataAccessBase
	{
		private const string dbServerAppSettingKey = "dbServer";
		private const string dbDatabaseAppSettingKey = "dbDatabase";
		private const string dbUserIdAppSettingKey = "dbUserId";
		private const string dbPasswordAppSettingKey = "dbPassword";

		private static string _dbServer = "";
		private static string _dbDatabase = "";
		private static string _dbUserId = "";
		private static string _dbPassword = "";

		static SqlDataAccessBase()
		{
			if(ConfigurationSettings.AppSettings[dbServerAppSettingKey] != null
				&& ConfigurationSettings.AppSettings[dbServerAppSettingKey].Length > 0)
				_dbServer = ConfigurationSettings.AppSettings[dbServerAppSettingKey];
			if(ConfigurationSettings.AppSettings[dbDatabaseAppSettingKey] != null
				&& ConfigurationSettings.AppSettings[dbDatabaseAppSettingKey].Length > 0)
				_dbDatabase = ConfigurationSettings.AppSettings[dbDatabaseAppSettingKey];
			if(ConfigurationSettings.AppSettings[dbUserIdAppSettingKey] != null
				&& ConfigurationSettings.AppSettings[dbUserIdAppSettingKey].Length > 0)
				_dbUserId = ConfigurationSettings.AppSettings[dbUserIdAppSettingKey];
			if(ConfigurationSettings.AppSettings[dbPasswordAppSettingKey] != null
				&& ConfigurationSettings.AppSettings[dbPasswordAppSettingKey].Length > 0)
				_dbPassword = ConfigurationSettings.AppSettings[dbPasswordAppSettingKey];
		}
		protected static string ConnectionString
		{
			get{return "server=" + _dbServer
						+ ";database=" + _dbDatabase
						+ ";uid=" + _dbUserId
						+ ";pwd=" + _dbPassword;}
		}
		/// <summary>
		/// Set DB Server
		/// </summary>
		/// <param name="value">DB Server name</param>
		public static void SetDbServer(string value)
		{
			_dbServer = value;
		}
		/// <summary>
		/// Set Database name
		/// </summary>
		/// <param name="value">Database name</param>
		public static void SetDbDatabase(string value)
		{
			_dbDatabase = value;
		}
		/// <summary>
		/// Set Database user id and password
		/// </summary>
		/// <param name="userId">Database user id</param>
		/// <param name="password">User's password</param>
		public static void SetDbUserIdAndPassword(string userId, string password)
		{
			_dbUserId = userId;
			_dbPassword = password;
		}

		public SqlDataAccessBase()
		{
		}
	}
}
